package com.sg.web;

import com.sg.bean.Join;
import com.sg.service.JobpersonService;
import com.sg.service.JoinService;
import com.sg.vo.JoinVO;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author lyx
 * 招聘信息（管理）控制器
 */
@Controller
public class JoinAdminController {
    @Autowired
    JoinService joinService;
    @Autowired
    JobpersonService jobpersonService;

    Logger logger = Logger.getLogger(JoinAdminController.class);

    @RequestMapping("/admin/joinlist")
    public String joinlist(Model model) {
        logger.info("joinlist---");
        List<JoinVO> joinlist = joinService.findAll();
        logger.info("joinlist size: " + joinlist.size());
        model.addAttribute("joinlist", joinlist);
        return "admin/joinlist";
    }

    @RequestMapping("/admin/toaddjoin")
    public String toaddjoin() {
        logger.info("toaddjoin---");
        return "admin/addjoin";
    }

    @RequestMapping("/admin/addjoin")
    public String addjoin(Join join) {
        logger.info(join);
        boolean flag = joinService.add(join);
        logger.info(flag);
        return "redirect:joinlist.action";//返回到列表控制器，重定向
    }

    @RequestMapping("/admin/deletejoin")
    public String deletejoin(int joinId) {
        //logger.info(Arrays.toString(joinId));
        boolean flag = joinService.delete(joinId);
        logger.info(flag);
        return "redirect:joinlist.action";
    }

    @RequestMapping("/admin/jobpersonlist")
    public String jobpersonlist(Model model) {
        logger.info("jobpersonlist---");
        List<JoinVO> jobpersonlist = joinService.findAll();
        logger.info("jobpersonlist size: " + jobpersonlist.size());
        model.addAttribute("jobpersonlist", jobpersonlist);
        return "admin/jobpersonlist";
    }

/*    @RequestMapping("/admin/deletejobperson")
    public String deletejobperson(int jpId) {
        //logger.info(Arrays.toString(joinId));
        boolean flag = jobpersonService.delete(jpId);
        logger.info(flag);
        return "redirect:joinlist.action";
    }*/
}
